.TH std::ranges::take_view::begin 3 "2024.06.10" "http://cppreference.com" "C++ Standard Libary"
.SH NAME
std::ranges::take_view::begin \- std::ranges::take_view::begin

.SH Synopsis
   constexpr auto begin() requires (!__SimpleView<V>);           \fB(1)\fP \fI(since C++20)\fP
   constexpr auto begin() const requires ranges::range<const V>; \fB(2)\fP \fI(since C++20)\fP

   Returns an iterator to the first element of the take_view.

   1) Returns a std::counted_iterator or a ranges::iterator_t<V>.
   2) Returns a std::counted_iterator or a ranges::iterator_t<const V>.

   Overload \fB(1)\fP does not participate in overload resolution if V is a simple view (that
   is, if V and const V are views with the same iterator and sentinel types).

.SH Parameters

   \fI(none)\fP

.SH Return value

   The result depends on the concepts satisfied by possibly const-qualified underlying
   view type Base_, which is V (for overload \fB(1)\fP) or const V (for overload \fB(2)\fP).

   Let base_ be the underlying view, count_ be the number passed to the constructor (0
   if default initialized).

   The underlying                           random_access_range
   view satisfies
         ...               yes                                 no
                                        std::counted_iterator(ranges::begin(base_),
               yes ranges::begin(base_)
   sized_range
                                        ranges::range_difference_t<Base_>(this->size()))
               no  std::counted_iterator(ranges::begin(base_), count_)

.SH Example


// Run this code

 #include <concepts>
 #include <forward_list>
 #include <iostream>
 #include <ranges>
 #include <string_view>
 #include <type_traits>
 using namespace std::literals;

 int main()
 {
     {
         static constexpr auto v = {"∀x"sv, "∃y"sv, "ε"sv, "δ"sv};
         auto view = std::ranges::take_view(v, 8);
         auto iter = view.begin();
         std::cout << *iter << '\\n';
         static_assert(
             std::ranges::sized_range<decltype(v)> and
             std::ranges::random_access_range<decltype(v)> and
             std::is_same_v<decltype(iter), decltype(std::ranges::begin(v))>
         );
     }

     {
         std::forward_list v = {"Ax"sv, "Ey"sv, "p"sv, "q"sv};
         auto view = std::ranges::take_view(v, 8);
         auto iter = view.begin();
         std::cout << *iter << '\\n';
         static_assert(
             not std::ranges::sized_range<decltype(v)> and
             not std::ranges::random_access_range<decltype(v)> and
             std::is_same_v<decltype(iter),
                 std::counted_iterator<
                     std::forward_list<std::string_view>::iterator>>
         );
     }
 }

.SH Output:

 ∀x
 Ax

   Defect reports

   The following behavior-changing defect reports were applied retroactively to
   previously published C++ standards.

     DR    Applied to              Behavior as published               Correct behavior
   P2393R1 C++20      implicit conversions between signed and unsigned made explicit
                      integer-class types might fail

.SH See also

   end              returns an iterator or a sentinel to the end
   (C++20)          \fI(public member function)\fP
   counted_iterator iterator adaptor that tracks the distance to the end of the range
   (C++20)          \fI(class template)\fP
   operator==       compares a sentinel with an iterator returned from take_view::begin
   (C++20)          \fI(function)\fP
